package com.heyu.cgsd.ui.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.heyu.cgsd.R
import com.heyu.cgsd.ui.adapter.BaseFragmentAdapter
import com.heyu.cgsd.ui.fragment.NormalFragment
import com.heyu.cgsd.ui.fragment.ScienceFragment
import com.heyu.cgsd.util.StatusBarUtil
import kotlinx.android.synthetic.main.activity_calculator.*
import kotlinx.android.synthetic.main.title_bar_base.*
import java.util.*

/**
 * Author:ZJC
 * Date:2020/2/6  20:15
 * Description:CalculatorActivity
 */
class CalculatorActivity : AppCompatActivity() {

    private var mode = 0
    
    var height = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStatusBar()
        setContentView(R.layout.activity_calculator)
        initView()
        initData()
    }

    private fun initData() {
        tv_title!!.text = "计算器"
        img_title!!.setImageResource(R.drawable.icon_switch)
        img_back!!.setImageResource(R.drawable.icon_back_black)
        mode = 0
        val list: MutableList<Fragment> = ArrayList()
        list.add(NormalFragment())
        list.add(ScienceFragment())
        val adapter = BaseFragmentAdapter(supportFragmentManager, list)
        vp_calc!!.adapter = adapter
    }

    private fun setStatusBar() {
        height = StatusBarUtil.getStatusBarHeight(this)
        //当FitsSystemWindows设置 true 时，会在屏幕最上方预留出状态栏高度的 padding
        StatusBarUtil.setRootViewFitsSystemWindows(this, true)
        //设置状态栏透明
        StatusBarUtil.setTranslucentStatus(this)
    }

    /**
     * 设置状态栏字体颜色
     *
     * @param colors 颜色值
     */
    private fun setStatusBarColor(colors: Int) {
        if (!StatusBarUtil.setStatusBarDarkTheme(this, true)) {
            StatusBarUtil.setStatusBarColor(this, colors)
        }
    }

    fun initView() {
        setStatusBarColor(-0xcccccd)
        tv_title!!.visibility = View.VISIBLE
        img_title!!.visibility = View.VISIBLE

        img_back.setOnClickListener {
            finish()
        }
        img_title.setOnClickListener {
            mode = if (mode == 0) 1 else 0
            vp_calc!!.currentItem = mode
        }
    }
}